{include file="common/head"/}
<div class="admin-main layui-anim layui-anim-upbit">
  <fieldset class="layui-elem-field layui-field-title">
    <legend>邮箱配置</legend>
  </fieldset>
  <form class="layui-form layui-form-pane" lay-filter="form-email">
    <div class="layui-form-item">
      <label class="layui-form-label">服务器</label>
      <div class="layui-input-4">
        <input type="text" lay-verify="required" name="smtp_server" placeholder="SMTP服务器" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">SMTP端口</label>
      <div class="layui-input-4">
        <input type="text" lay-verify="required" name="smtp_port" placeholder="SMTP端口" value="" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">发件人</label>
      <div class="layui-input-4">
        <input type="text" name="email_id" lay-verify="required" placeholder="发信人" value="" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">发件邮箱</label>
      <div class="layui-input-4">
        <input type="text" name="smtp_user" lay-verify="required" placeholder="发信人邮件地址" value="" class="layui-input">
      </div>
    </div>

    <div class="layui-form-item">
      <label class="layui-form-label">身份验证码</label>
      <div class="layui-input-3">
        <input type="password" name="smtp_pwd" lay-verify="required" placeholder="SMTP身份验证码" value="" class="layui-input">
      </div>
    </div>

    <div class="layui-form-item">
      <label class="layui-form-label">测试邮箱</label>
      <div class="layui-input-3">
        <input type="text" name="test_eamil" id="test_eamil" placeholder="测试接收邮件地址" value="" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item layui-form-text">
      <label class="layui-form-label">测试邮件内容</label>
      <div class="layui-input-block">
        <textarea name="test_eamil_info" id="test_eamil_info" placeholder="{:lang('pleaseEnter')}测试内容" class="layui-textarea"></textarea>
      </div>
    </div>




    <div class="layui-form-item">
      <div class="layui-input-block">
        <button type="button" class="layui-btn" lay-submit="" lay-filter="submit">{:lang('submit')}</button>
        <button type="reset" class="layui-btn layui-btn-primary">{:lang('reset')}</button>
        <button type="button" class="layui-btn layui-btn-normal" id="trySend">测试发送</button>
      </div>
    </div>
  </form>
</div>
{include file="common/foot"/}
<script>
  layui.use(['form', 'layer'], function () {
    var form = layui.form,layer = layui.layer,$= layui.jquery;
    //发送测试邮件
    form.val("form-email", {$info|raw})
    $('#trySend').click(function(){
      loading =layer.load(1, {shade: [0.1,'#fff']});
      var email = $('#test_eamil').val();
      $.post("{:url('trySend')}",{email:email},function(res){
        layer.close(loading);
        if(res.code > 0){
          layer.msg(res.msg,{time:1800});
        }else{
          layer.msg(res.msg,{time:1800});
        }
      });
    });
    //提交监听
    form.on('submit(submit)', function (data) {
      loading =layer.load(1, {shade: [0.1,'#fff']});
      $.post("{:url('system/email')}",data.field,function(res){
        layer.close(loading);
        if(res.code > 0){
          layer.msg(res.msg,{icon: 1, time: 1000},function(){
            location.href = res.url;
          });
        }else{
          layer.msg(res.msg,{icon: 2, time: 1000});
        }
      });
    })
  })
</script>
</body>
</html>